package jam.model;

import jam.network.*;
import java.util.*;
import java.util.concurrent.*;

//
// =============================================================================
//

public class ServerModel {
    private Map<String, Channel> channels;
    private Map<String, ClientController> loggedIn;
       
    //
    // =========================================================================
    //
      
    public Channel getChannel(String channelName) {
        return channels.get(channelName);
    }
    
    public boolean channelExists(String channelName) {
        return this.channels.containsKey(channelName);
    }
    
    public void addChannel(Channel c) {
        this.channels.put(c.getName(), c);
    }
    
    public boolean removeChannel(String channelName) {
        return this.channels.remove(channelName) != null;
    }
    
    //
    // =========================================================================
    //
             
    public Set<String> getLoggedInSet() {
        return Collections.unmodifiableSet(this.loggedIn.keySet());
    }
    public Map<String, ClientController> getLoggedInMap() {
        return Collections.unmodifiableMap(this.loggedIn);
    }
    public ClientController getLoggedInController(String username) {
        return this.loggedIn.get(username);
    }
    
    public boolean isLoggedIn(String u) {
        return this.loggedIn.containsKey(u.toLowerCase());
    }   
    
    public void addLoggedIn(String u, ClientController c) {
        this.loggedIn.put(u.toLowerCase(), c);
    }
    public void removeLoggedIn(String username) {
        this.loggedIn.remove(username.toLowerCase());
    }
    
    //
    // =========================================================================
    //
    
    public ServerModel() {
        this.loggedIn = new ConcurrentHashMap<String, ClientController>();
        this.channels = new ConcurrentHashMap<String, Channel>();
    }
}